package com.egao.common.module.pepesi.controller;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.pepesi.entity.vo.PepsiTeacherVO;
import com.egao.common.module.pepesi.service.PepsiTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 管理端学生的一百件事
 *
 * @author pyx
 * @date 2021/5/14
 */
@Api(tags = "管理端学生的一百件事")
@RestController
@RequestMapping("${api}")
public class PepsiTeacherController {
    @Autowired
    private PepsiTeacherService pepsiTeacherService;

    @PreAuthorize("hasAuthority('pepsi:teacher:list')")
    @ApiOperation("管理端学生的一百件事")
    @OperLog(value = "管理端学生的一百件事管理", desc = "分页查询学生一百件事信息")
    @GetMapping("/pepsi/teacher/page")
    public PageResult<PepsiTeacherVO> page(HttpServletRequest request) {
        PageParam<PepsiTeacherVO> pageParam = new PageParam<>(request);
        return new PageResult<>(pepsiTeacherService.listPage(pageParam),pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('pepsi:teacher:list')")
    @ApiOperation("统计完成25%,50%,75%以上的人")
    @OperLog(value = "管理端学生的一百件事管理", desc = "统计完成25%,50%,75%以上的人")
    @GetMapping("/pepsi/student/statistics")
    public JsonResult pepsiStatistics(HttpServletRequest request) {
        Map<String, Object> pageParam = new PageParam<>(request).getNoPageParam();
        return pepsiTeacherService.pepsiStatistics(pageParam);
    }

    @PreAuthorize("hasAuthority('pepsi:teacher:detail')")
    @ApiOperation("查询学生100件事")
    @OperLog(value = "学生的100件事", desc = "查询学生的100件事树形结构")
    @GetMapping("/pepsi/teacher/tree")
    public JsonResult page(Integer studentId,Integer finishState) {
        return pepsiTeacherService.pepsiStudentData(studentId,finishState);
    }

    @PreAuthorize("hasAuthority('pepsi:teacher:export')")
    @OperLog(value = "管理端学生100件事", desc = "导出", result = true)
    @ApiOperation(value = "导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "导出类型 text文本 code代码", required = true, dataType = "string"),
            @ApiImplicitParam(name = "StudentExcelVO", value = "StudentExcelVO", required = false, dataType = "StudentExcelVO")
    })
    @GetMapping("/pepsi/teacher/export")
    public void export(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> pageParam = new PageParam<>(request).getNoPageParam();
        pepsiTeacherService.exportExcel(pageParam, response);
    }
}